import { IPSControl } from '../ipscontrol';
import { IPSDBContainerPortletPart } from './ipsdbcontainer-portlet-part';
import { IPSDBPortletPart } from './ipsdbportlet-part';
import { PSDBPortletPartImpl } from './psdbportlet-part-impl';
import { IPSLayout } from '../layout/ipslayout';

export class PSDBContainerPortletPartImpl extends PSDBPortletPartImpl implements IPSDBContainerPortletPart {
  protected contentpscontrol: IPSControl | null = null;

  getContentPSControl(): IPSControl | null {
    if (this.contentpscontrol != null) return this.contentpscontrol;
    const value = this.M.getContentPSControl;
    if (value == null) {
      return null;
    }
    this.contentpscontrol = this.findPSControl(value);
    return this.contentpscontrol;
  }

  get contentPSControl(): IPSControl | null {
    return this.getContentPSControl();
  }

  getContentPSControlMust(): IPSControl {
    const value = this.getContentPSControl();
    if (value == null) {
      throw new Error('未指定内容部件');
    }
    return value;
  }

  protected pslayout: IPSLayout | null = null;

  getPSLayout(): IPSLayout | null {
    if (this.pslayout != null) return this.pslayout;
    const value = this.M.getPSLayout;
    if (value == null) {
      return null;
    }
    this.pslayout = this.getPSModel4('control.layout.IPSLayout', value, 'getPSLayout') as IPSLayout;
    return this.pslayout;
  }

  get psLayout(): IPSLayout | null {
    return this.getPSLayout();
  }

  getPSLayoutMust(): IPSLayout {
    const value = this.getPSLayout();
    if (value == null) {
      throw new Error('未指定容器布局');
    }
    return value;
  }

  get portletType(): 'LIST' | 'CHART' | 'VIEW' | 'HTML' | 'TOOLBAR' | 'ACTIONBAR' | 'CUSTOM' | 'APPMENU' | 'CONTAINER' | 'RAWITEM' {
    return this.M.portletType;
  }

  get cls(): string {
    return 'PSDBContainerPortletPartImpl';
  }

  instanceof(cls: string): boolean {
    if (cls == 'control.dashboard.IPSDBContainerPortletPart' || cls == 'control.dashboard.IPSDashboardContainer' || cls == 'control.layout.IPSLayoutContainer') return true;
    return super.instanceof(cls);
  }
}
